//
//  PlayBgin.m
//  Courses
//
//  Created by YiXuePxh on 15/4/22.
//  Copyright (c) 2015年 boyibang. All rights reserved.
//

#import "PlayBgin.h"
#import "Request.h"
@implementation PlayBgin


-(id)initWithJsonDict:(NSDictionary* )jsonDict{
    self.paymentNo = jsonDict[@"paymentNo"];
    self.platform = jsonDict[@"platform"];
    if ([jsonDict[@"platformKeyInfo"] isKindOfClass:[NSDictionary class]]) {
        self.partner = jsonDict[@"platformKeyInfo"][@"partner"];
        self.seller = jsonDict[@"platformKeyInfo"][@"seller"];
        self.rsaPrivatekey = jsonDict[@"platformKeyInfo"][@"rsaPrivatekey"];
        self.rsaPublicKey = jsonDict[@"platformKeyInfo"][@"rsaPublicKey"];
        self.notifyUrl = jsonDict[@"platformKeyInfo"][@"notifyUrl"];
    }
    return self;
}
+(PlayBgin* )getPlayBginWithAgencyid:(NSString* ) agencyid
                              UserId:(NSString* ) userId
                            Platform:(NSString* ) platform
                             OrderId:(NSString* ) orderId
                          RealAmount:(NSString* ) realAmount{
    PlayBgin* playBgin;
    Request* request = [Request requestWithName:@"pay_begin"];
    request.body[@"sourceId"] = @"2";
    request.body[@"deviceNo"] = @"IOS12345";
    NSDictionary* dicInfo = [[NSBundle mainBundle] infoDictionary];
    request.body[@"version"] = [dicInfo objectForKey:@"CFBundleShortVersionString"];
    request.body[@"agencyId"] = agencyid;
    request.body[@"userId"] = userId;
    request.body[@"platform"] = platform;
    request.body[@"orderId"] = orderId;
    request.body[@"realAmount"] = realAmount;
    Response* response = [request response];
    if (!response.result) {
        return nil;
    }
    if (response.result) {
        if ([response.content[@"payment"] isKindOfClass:[NSDictionary class]]) {
            playBgin = [[PlayBgin alloc] initWithJsonDict:response.content[@"payment"]];
        }
    }
    return playBgin;
}

@end
